import React, { useEffect, useState } from 'react';
import {
  List,
  WingBlank,
} from 'antd-mobile';
import { getUserInfoByCode } from '../../api/wecode';

const { Item } = List;

function Auth() {
  const u: BaseObject = {};
  const [userInfo, setUserInfo] = useState(u);
  useEffect(() => {
    window.HWH5.getAuthCode().then(async (res) => {
      const { data } = await getUserInfoByCode(res.code);
      setUserInfo(data);
      console.log('获取用户信息', data);
    }).catch((error) => {
      console.log('获取异常', error);
    });
  }, []);
  return (
    <WingBlank>
      <List renderHeader={() => '用户信息'}>
        {Object.keys(userInfo).map((name: string) => (
          <Item extra={userInfo[name]}>{name}</Item>
        ))}
      </List>
    </WingBlank>
  );
}
export default Auth;
